﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StoragePeriod.Common
{
    public static class Utility
    {
        public static string GetMD5PassWord(string sDataIn, string move)
        { 
            System.Security.Cryptography.MD5CryptoServiceProvider
            md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] bytValue, bytHash;
            bytValue = System.Text.Encoding.UTF8.GetBytes(move + sDataIn);
            bytHash = md5.ComputeHash(bytValue);
            md5.Clear();
            string sTemp = "";
            for (int i = 0; i < bytHash.Length; i++)
            {
                sTemp += bytHash[i].ToString("x").PadLeft(2, '0');
            }
            return sTemp;
       
        }

        public static string NewPrivCode()
        {
            return GenerateStringID() ;
        }
        private static string GenerateStringID()
        {
            long i = 1;

            foreach (byte b in Guid.NewGuid().ToByteArray())
            {
                i *= ((int)b + 1);
            }
            return string.Format("{0:x}", i - DateTime.Now.Ticks);
        }

        private static long GenerateIntID()
        {
            byte[] buffer = Guid.NewGuid().ToByteArray();

            return BitConverter.ToInt64(buffer, 0);
        }
    }
}
